import Vue from 'vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import dataV from '@jiaminghi/data-view'
import VueClipboard from 'vue-clipboard2';
import axios from 'axios';
import router from './router/router.js';
import './permission.js'
import base from "./base"
import App from './App.vue'
import './assets/style/index.css'
// import './assets/js/jsplumb'
import { url } from '@/config'
import './icons/index'
// import '@/mock/'
import store from './store/index.js'
import bootstrap from './core/bootstrap'
// import VForm from 'vform-builds'  //引入VForm库
// import VFormRender from 'vform-builds/dist/VFormRender.umd.min.js'
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css'

import '@/assets/icon/iconfont.js'
import '@/assets/icon/iconfont.css'
import '@/assets/icon/logoIcon/iconfont.css'

import * as echarts from 'echarts'
// import VueGridLayout from 'vue-grid-layout';

import vform from 'vform'
import '@public/cdn/vform/VFormDesigner.css'  //引入VForm样式
// import 'vjmap/dist/vjmap.min.css'
// import '@/assets/js/vform/VFormRender.css'
// import vform from 'vform-builds'  //引入VForm库


import Node from './page/app/workflow/components/node/node.vue'
Vue.component('Node', Node)

// import 'element-ui/lib/theme-chalk/index.css'  //引入element-ui样式
// import 'vform-builds/dist/VFormDesigner.css'  //引入VForm样式
import UserAuth from '@/util/userAuth'


import UmyUi from 'umy-ui'  //解决大数据问题组件
import 'umy-ui/lib/theme-chalk/index.css';// 引入样式
Vue.use(UmyUi);

// import VueFullscreen from 'vue-fullscreen'
// Vue.use(VueFullscreen)

//注册自定义组件
import './components/'
//导入主题文件
import '@/theme/index.js'
window.axios = axios;
window.vformUploadUrlPrefix = window.location.origin
Vue.config.productionTip = false
Vue.prototype.url = url;
Vue.use(VueClipboard)
Vue.use(window.AVUE, {
  size: 'mini'
});
Vue.use(Antd);
Vue.use(ElementUI);
Vue.use(dataV);
Vue.use(base);
Vue.use(vform)
//<script src="https://data.avuejs.com/cdn/element-ui/2.13.2/index.js" charset="utf-8"></script>
// Vue.use(VFormRender)  //全局注册VFormRender等组件
Vue.prototype.$echarts = echarts

const initVue = () => {
  new Vue({
    router,
    store,
    created: () => {
      const loadSDK = function(src){
        let head = document.getElementsByTagName("head")[0]
        let script = document.createElement("script")
        script.type = "text/javascript"
        script.onload = script.onreadystatechange = function () {
          if (
            !this.readyState ||
            this.readyState === "loaded" ||
            this.readyState === "complete"
          ) {
            script.onload = script.onreadystatechange = null
          }
        }
        script.src = src
        head.appendChild(script)
      }
      console.log('load sdk')
      loadSDK(`/2d/build/CGSMapSDKLoader.min.js`);
      loadSDK(`/3d/build/CGSJsSDKLoader.min.js`);
      loadSDK(`/earth/build/CGSGlobeSDKLoader.min.js`);
      // loadSDK(`//${window.location.hostname}:20000/build/CGSJsSDKLoader.min.js`)
      // loadSDK(`//${window.location.hostname}:40000/build/CGSMapSDKLoader.min.js`)
      // loadSDK(`//${window.location.hostname}:30000/build/CGSGlobeSDKLoader.min.js`)
  
      
  
      bootstrap()
      
      
    },
    render: h => h(App)
  }).$mount('#app')
}
if(window.name.indexOf('childWindow') > -1){
    const messageListen = (event)=>{
      let result = event.data;
      if(typeof(result)==='object' && 'params' in result && 'type' in result && result.type === 'cgsLoginWindow'){
        new UserAuth(result.params)
        initVue()
        window.removeEventListener("message", messageListen);
      }
      
    }
    window.addEventListener("message", messageListen, false);
    if(window.parent === window){
      window.opener.postMessage('loaded', '*')
    } else {
      window.parent.postMessage('loaded', '*')
    }
    // window.parent.postMessage('start', '*')
  
} else {
  initVue()
}

